package com.tal.bcc.pad.cloud.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

public class DateUtils {
    public DateUtils() {
    }

    public static String getCurrentTimeByCalendar(Calendar cd) {
        return getCurrentTimeByCalendar(cd, Locale.US);
    }

    public static String getCurrentTimeByCalendar(Calendar cd, Locale locale) {
        SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", locale);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        String dateTime = sdf.format(cd.getTime());
        return dateTime;
    }
    public static String getCurrentDate() {
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8:00");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        simpleDateFormat.setTimeZone(timeZone);
        return simpleDateFormat.format(new Date());
    }

    public static String getCurrentTimeByCalendar() {
        Calendar cd = new GregorianCalendar();
        return getCurrentTimeByCalendar(cd);
    }

    public static String getCurrentTimeByCalendarAddSeconds(Integer durationSeconds) {
        Calendar cd = new GregorianCalendar();
        cd.add(13, durationSeconds);
        return getCurrentTimeByCalendar(cd);
    }

    public static String getCurrentTimeByCalendarAddSeconds(String durationSeconds) {
        Calendar cd = new GregorianCalendar();
        cd.add(13, Integer.valueOf(durationSeconds));
        return getCurrentTimeByCalendar(cd);
    }

    public static String getUtc(String time) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.US);
        Date gmt = sdf.parse(time);
        String utc = sf.format(gmt);
        return utc;
    }
}
